/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-05-25 19:29:07
 * @LastEditTime: 2024-06-30 12:15:18
 * @FilePath: /nest_study/server/src/modules/system/menu/entities/menu.entity.ts
 */
import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { BaseEntity } from 'src/common/entites/base';
import { MenuTypes } from 'src/common/enum/menu';
import { SystemRoleEntity } from '../../role/entities/role.entity';

@Entity('sys_menu', {
    comment: '菜单权限表',
})
export class SystemMenuEntity extends BaseEntity {
    @ApiProperty({ type: Number, description: '菜单ID' })
    @PrimaryGeneratedColumn({ type: 'int', name: 'menu_id', comment: '菜单ID' })
    public id: number;

    @ApiProperty({ type: String, description: '菜单名称' })
    @Column({ type: 'varchar', name: 'menu_name', length: 50, comment: '菜单名称' })
    public name: string;

    @ApiProperty({ type: String, description: '父菜单ID' })
    @Column({ type: 'int', name: 'parent_id', comment: '父菜单ID' })
    public parentId: number;

    @Column({ type: 'varchar', name: 'path', length: 255, nullable: true, comment: '组件路径' })
    public path: string;

    //是否为外链（0是 1否）
    @Column({ type: 'char', name: 'external', default: '1', comment: '是否为外链' })
    public external: string;

    //是否显示（0是 1否）
    @Column({ type: 'char', name: 'visible', default: '0', comment: '是否显示' })
    public visible: string;

    //菜单类型（C目录 M菜单 B按钮）
    @Column({ type: 'char', name: 'menu_type', length: 1, default: MenuTypes.MENU, comment: '菜单类型' })
    public menuType: string;

    @Column({ type: 'varchar', name: 'icon', length: 100, default: '', comment: '菜单图标' })
    public icon: string;

    @Column({ type: 'int', name: 'post_sort', default: 0, comment: '显示顺序' })
    public sort: number;

    @ManyToMany(() => SystemRoleEntity, (role) => role.menus)  
    roles: SystemRoleEntity[];  
}
